package com.newzqxq.common.utils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 银行卡工具类
 * Created by 东方 on 2017/7/26.
 */
public class CardUtils {

    public static String[] bankNames = {"中国银行", "中国农业银行", "中国建设银行", "中国工商银行", "中国邮政储蓄银行", "招商银行", "中信银行", "光大银行", "汇丰银行", "兴业银行",
            "浦发银行", "平安银行", "广发银行", "中国民生银行", "华夏银行", "深圳农村商业银行", "广西北部湾银行", "上海农村商业银行", "北京银行", "威海市商业银行",
            "周口银行", "库尔勒市商业银行", "顺德农商银行", "湖北省农村信用社", "无锡农村商业银行", "朝阳银行", "浙商银行", "邯郸银行", "东莞银行", "遵义市商业银行",
            "绍兴银行", "贵州省农村信用社", "张家口市商业银行", "锦州银行", "平顶山银行", "汉口银行", "上海浦东发展银行", "宁夏黄河农村商业银行", "广东南粤银行", "广州农商银行",
            "苏州银行", "杭州银行", "衡水银行", "湖北银行", "嘉兴银行", "华融湘江银行", "丹东银行", "安阳银行", "恒丰银行", "国家开发银行",
            "江苏太仓农村商业银行", "南京银行", "郑州银行", "德阳商业银行", "宜宾市商业银行", "四川省农村信用", "昆仑银行", "莱商银行", "尧都农商行", "重庆三峡银行",
            "富滇银行", "江苏省农村信用联合社", "济宁银行", "晋城银行", "阜新银行", "武汉农村商业银行", "湖北银行宜昌分行", "台州银行", "泰安市商业银行", "许昌银行",
            "宁夏银行", "徽商银行", "九江银行", "农信银清算中心", "浙江民泰商业银行", "廊坊银行", "鞍山银行", "昆山农村商业银行", "玉溪市商业银行", "大连银行",
            "东莞农村商业银行", "广州银行", "宁波银行", "营口银行", "陕西信合", "桂林银行", "青海银行", "成都农商银行", "青岛银行", "东亚银行",
            "湖北银行黄石分行", "温州银行", "天津农商银行", "齐鲁银行", "广东省农村信用社联合社", "浙江泰隆商业银行", "赣州银行", "贵阳市商业银行", "重庆银行", "龙江银行",
            "南充市商业银行", "三门峡银行", "常熟农村商业银行", "上海银行", "吉林银行", "常州农村信用联社", "潍坊银行", "张家港农村商业银行", "福建海峡银行", "浙江省农村信用社联合社",
            "兰州银行", "晋商银行", "渤海银行", "浙江稠州商业银行", "阳泉银行", "盛京银行", "西安银行", "包商银行", "江苏银行", "抚顺银行",
            "河南省农村信用", "交通银行", "邢台银行", "湖南省农村信用社", "东营市商业银行", "鄂尔多斯银行", "北京农村商业银行", "信阳银行", "自贡市商业银行", "成都银行",
            "韩亚银行", "洛阳银行", "广东发展银行", "齐商银行", "开封市商业银行", "内蒙古银行", "重庆农村商业银行", "石嘴山银行", "德州银行", "上饶银行",
            "乐山市商业银行", "江西省农村信用", "晋中市商业银行", "湖州市商业银行", "南海农村信用联社", "新乡银行", "江苏江阴农村商业银行", "云南省农村信用社", "广西省农村信用", "驻马店银行",
            "安徽省农村信用社", "甘肃省农村信用", "辽阳市商业银行", "吉林农信", "乌鲁木齐市商业银行", "中山小榄村镇银行", "长沙银行", "金华银行", "河北银行", "鄞州银行",
            "临商银行", "承德银行", "山东农信", "南昌银行", "天津银行", "吴江农商银行", "城市商业银行资金清算中心", "河北省农村信用社"};

    public static String[] bankCode = {"BC", "ABC", "CCB", "ICBC", "PSBC", "CMB", "CITIC", "CEB", "HSBC", "CIB",
            "SPDB", "SPABANK", "CGB", "CMBC", "HXBANK", "SRCB", "BGB", "SHRCB", "BJBANK", "WHCCB",
            "BOZK", "KORLABANK", "SDEB", "HURCB", "WRCB", "BOCY", "CZBANK", "HDBANK", "BOD", "ZYCBANK",
            "SXCB", "GZRCU", "ZJKCCB", "BOJZ", "BOP", "HKB", "SPDB", "NXRCU", "NYNB", "GRCB",
            "BOSZ", "HZCB", "HSBK", "HBC", "JXBANK", "HRXJB", "BODD", "AYCB", "EGBANK", "CDB",
            "TCRCB", "NJCB", "ZZBANK", "DYCB", "YBCCB", "SCRCU", "KLB", "LSBANK", "YDRCB", "CCQTGB",
            "FDB", "JSRCU", "JNBANK", "JINCHB", "FXCB", "WHRCB", "HBYCBANK", "TZCB", "TACCB", "XCYH",
            "NXBANK", "HSBANK", "JJBANK", "NHQS", "MTBANK", "LANGFB", "ASCB", "KSRB", "YXCCB", "DLB",
            "DRCBCL", "GCB", "NBBANK", "BOYK", "SXRCCU", "GLBANK", "BOQH", "CDRCB", "QDCCB", "HKBEA",
            "HBHSBANK", "WZCB", "TRCB", "QLBANK", "GDRCC", "ZJTLCB", "GZB", "GYCB", "CQBANK", "DAQINGB",
            "CGNB", "SCCB", "CSRCB", "SHBANK", "JLBANK", "CZRCB", "BANKWF", "ZRCBANK", "FJHXBC", "ZJNX",
            "LZYH", "JSB", "BOHAIB", "CZCB", "YQCCB", "SJBANK", "XABANK", "BSB", "JSBANK", "FSCB",
            "HNRCU", "COMM", "XTB", "HNRCC", "DYCCB", "ORBANK", "BJRCB", "XYBANK", "ZGCCB", "CDCB",
            "HANABANK", "LYBANK", "GDB", "ZBCB", "CBKF", "H3CB", "CRCBANK", "SZSBK", "DZBANK", "SRBANK",
            "LSCCB", "JXRCU", "JZBANK", "HZCCB", "NHB", "XXBANK", "JRCB", "YNRCC", "GXRCU", "BZMD",
            "ARCU", "GSRCU", "LYCB", "JLRCU", "URMQCCB", "XLBANK", "CSCB", "JHBANK", "BHB", "NBYZ",
            "LSBC", "BOCD", "SDRCU", "NCB", "TCCB", "WJRCB", "CBBQS", "HBRCU"};

    public static Map<String, String> getBankInfo(String bankNum) {
        Map<String, String> infoBean = new HashMap<>();
        if (bankNum.startsWith("436742") || bankNum.startsWith("436745") && bankNum.startsWith("622280")) {
            infoBean.put("bankName", "中国建设银行");
            infoBean.put("bankCode", "CCB");
            return infoBean;
        }
        if (bankNum.startsWith("458123") || bankNum.startsWith("521899") && bankNum.startsWith("622260")) {
            infoBean.put("bankName", "交通银行");
            infoBean.put("bankCode", "COMM");
            return infoBean;
        }
        if (bankNum.startsWith("402674") || bankNum.startsWith("622892")) {
            infoBean.put("bankName", "上海银行");
            infoBean.put("bankCode", "SHBANK");
            return infoBean;
        }
        if (bankNum.startsWith("622188")) {
            infoBean.put("bankName", "中国邮政储蓄银行");
            infoBean.put("bankCode", "PSBC");
            return infoBean;
        }
        if (bankNum.startsWith("602969")) {
            infoBean.put("bankName", "北京银行");
            infoBean.put("bankCode", "BJBANK");
            return infoBean;
        }
        if (bankNum.startsWith("622760") || bankNum.startsWith("409666") || bankNum.startsWith("438088") ||
                bankNum.startsWith("622752")) {
            infoBean.put("bankName", "中国银行");
            infoBean.put("bankCode", "BOC");
            return infoBean;
        }

        if (bankNum.startsWith("427020") || bankNum.startsWith("427030") || bankNum.startsWith("530990") ||
                bankNum.startsWith("622230") || bankNum.startsWith("622235") || bankNum.startsWith("622210") ||
                bankNum.startsWith("622215") || bankNum.startsWith("622200") || bankNum.startsWith("955880")) {
            infoBean.put("bankName", "中国工商银行");
            infoBean.put("bankCode", "ICBC");
            return infoBean;
        }

        if (bankNum.startsWith("622568") || bankNum.startsWith("520152") || bankNum.startsWith("520382") ||
                bankNum.startsWith("911121") || bankNum.startsWith("548844")) {
            infoBean.put("bankName", "广东发展银行");
            infoBean.put("bankCode", "GDB");
            return infoBean;
        }

        if (bankNum.startsWith("512431") || bankNum.startsWith("520194") || bankNum.startsWith("622318") ||
                bankNum.startsWith("622778") || bankNum.startsWith("622282")) {
            infoBean.put("bankName", "宁波银行");
            infoBean.put("bankCode", "NBBANK");
            return infoBean;
        }

        if (bankNum.startsWith("407405") || bankNum.startsWith("517636") || bankNum.startsWith("512466") ||
                bankNum.startsWith("415599") || bankNum.startsWith("421870") || bankNum.startsWith("622622") ||
                bankNum.startsWith("528948") || bankNum.startsWith("552288") || bankNum.startsWith("556610") ||
                bankNum.startsWith("622600") || bankNum.startsWith("622601") || bankNum.startsWith("622602") ||
                bankNum.startsWith("622603") || bankNum.startsWith("421869") || bankNum.startsWith("421871") ||
                bankNum.startsWith("628258")) {

            infoBean.put("bankName", "中国民生银行");
            infoBean.put("bankCode", "CMBC");
            return infoBean;
        }

        if (bankNum.startsWith("418152") || bankNum.startsWith("456418") || bankNum.startsWith("622521") ||
                bankNum.startsWith("404738") || bankNum.startsWith("404739") || bankNum.startsWith("498451") ||
                bankNum.startsWith("622517") || bankNum.startsWith("622518") || bankNum.startsWith("515672") ||
                bankNum.startsWith("517650") || bankNum.startsWith("525998") || bankNum.startsWith("356850") ||
                bankNum.startsWith("356851") || bankNum.startsWith("356852")) {
            infoBean.put("bankName", "上海浦东发展银行");
            infoBean.put("bankCode", "SPDB");
            return infoBean;
        }
        if (bankNum.startsWith("406254") || bankNum.startsWith("622655") || bankNum.startsWith("622650") ||
                bankNum.startsWith("622658") || bankNum.startsWith("356839") || bankNum.startsWith("486497") ||
                bankNum.startsWith("481699") || bankNum.startsWith("543159") || bankNum.startsWith("425862") ||
                bankNum.startsWith("406252") || bankNum.startsWith("356837") || bankNum.startsWith("356838") ||
                bankNum.startsWith("356840") || bankNum.startsWith("622161") || bankNum.startsWith("628201") ||
                bankNum.startsWith("628202")) {
            infoBean.put("bankName", "中国光大银行");
            infoBean.put("bankCode", "CEB");
            return infoBean;
        }

        if (bankNum.startsWith("622155") || bankNum.startsWith("622156") || bankNum.startsWith("528020") ||
                bankNum.startsWith("526855")) {
            infoBean.put("bankName", "平安银行");
            infoBean.put("bankCode", "SPABANK");
            return infoBean;
        }

        if (bankNum.startsWith("539867") || bankNum.startsWith("528709") || bankNum.startsWith("523959") ||
                bankNum.startsWith("622637") || bankNum.startsWith("622636") || bankNum.startsWith("528708") ||
                bankNum.startsWith("539868")) {
            infoBean.put("bankName", "华夏银行");
            infoBean.put("bankCode", "HXBANK");
            return infoBean;
        }

        if (bankNum.startsWith("518710") || bankNum.startsWith("518718") || bankNum.startsWith("622588") ||
                bankNum.startsWith("622575") || bankNum.startsWith("545947") || bankNum.startsWith("521302") ||
                bankNum.startsWith("439229") || bankNum.startsWith("552534") || bankNum.startsWith("622577") ||
                bankNum.startsWith("622579") || bankNum.startsWith("439227") || bankNum.startsWith("479229") ||
                bankNum.startsWith("356890") || bankNum.startsWith("356889") || bankNum.startsWith("356885") ||
                bankNum.startsWith("439188") || bankNum.startsWith("545948") || bankNum.startsWith("545623") ||
                bankNum.startsWith("552580") || bankNum.startsWith("552581") || bankNum.startsWith("552582") ||
                bankNum.startsWith("552583") || bankNum.startsWith("552584") || bankNum.startsWith("552585") ||
                bankNum.startsWith("552586") || bankNum.startsWith("552588") || bankNum.startsWith("552589") ||
                bankNum.startsWith("645621") || bankNum.startsWith("545619") || bankNum.startsWith("356886") ||
                bankNum.startsWith("622578") || bankNum.startsWith("622576") || bankNum.startsWith("622581") ||
                bankNum.startsWith("439228") || bankNum.startsWith("439225") || bankNum.startsWith("439226") ||
                bankNum.startsWith("628262") || bankNum.startsWith("628362") || bankNum.startsWith("628362") ||
                bankNum.startsWith("628262")) {
            infoBean.put("bankName", "招商银行");
            infoBean.put("bankCode", "CMB");
            return infoBean;
        }

        if (bankNum.startsWith("628206") || bankNum.startsWith("628208") || bankNum.startsWith("628209")
                || bankNum.startsWith("404174") || bankNum.startsWith("404171") || bankNum.startsWith("404157")
                || bankNum.startsWith("433668") || bankNum.startsWith("622688") || bankNum.startsWith("622689")
                || bankNum.startsWith("403392") || bankNum.startsWith("403393") || bankNum.startsWith("404158")
                || bankNum.startsWith("404159") || bankNum.startsWith("404172") || bankNum.startsWith("404173")
                || bankNum.startsWith("433666") || bankNum.startsWith("433667") || bankNum.startsWith("433669")
                || bankNum.startsWith("400360") || bankNum.startsWith("514906") || bankNum.startsWith("558916")
                || bankNum.startsWith("403391") || bankNum.startsWith("622680") || bankNum.startsWith("556617")
                || bankNum.startsWith("622919") || bankNum.startsWith("376969") || bankNum.startsWith("520108")
                || bankNum.startsWith("622690") || bankNum.startsWith("518212") || bankNum.startsWith("622916")
                || bankNum.startsWith("622918") || bankNum.startsWith("376966") || bankNum.startsWith("376968")) {
            infoBean.put("bankName", "中信银行");
            infoBean.put("bankCode", "CITIC");
            return infoBean;
        }
        if (bankNum.startsWith("622922") || bankNum.startsWith("486861") || bankNum.startsWith("523036")
                || bankNum.startsWith("451290") || bankNum.startsWith("486494") || bankNum.startsWith("486493")
                || bankNum.startsWith("524070") || bankNum.startsWith("527414") || bankNum.startsWith("622901")
                || bankNum.startsWith("622902") || bankNum.startsWith("451289")) {
            infoBean.put("bankName", "兴业银行");
            infoBean.put("bankCode", "CIB");
            return infoBean;
        }

        if (bankNum.startsWith("622837") || bankNum.startsWith("622836") || bankNum.startsWith("622848")
                || bankNum.startsWith("404117") || bankNum.startsWith("53591") || bankNum.startsWith("404118")
                || bankNum.startsWith("404120") || bankNum.startsWith("49102") || bankNum.startsWith("519413")
                || bankNum.startsWith("520082") || bankNum.startsWith("520083") || bankNum.startsWith("558730")
                || bankNum.startsWith("403361") || bankNum.startsWith("519412") || bankNum.startsWith("404121")
                || bankNum.startsWith("404119") || bankNum.startsWith("552599")) {
            infoBean.put("bankName", "中国农业银行");
            infoBean.put("bankCode", "ABC");
            return infoBean;
        }
        if (bankNum.startsWith("4367") || bankNum.startsWith("6227") || bankNum.startsWith("0130") && bankNum.length() == 19) {
            infoBean.put("bankName", "中国建设银行");
            infoBean.put("bankCode", "CCB");
            return infoBean;
        }

        if (bankNum.startsWith("62288") || bankNum.startsWith("95599") && bankNum.length() == 19) {
            infoBean.put("bankName", "中国农业银行");
            infoBean.put("bankCode", "ABC");
            return infoBean;
        }

        if (bankNum.startsWith("50-3")) {
            infoBean.put("bankName", "中国农业银行");
            infoBean.put("bankCode", "ABC");
            return infoBean;
        }
        if (bankNum.startsWith("3") && bankNum.length() == 15) {
            infoBean.put("bankName", "中国农业银行");
            infoBean.put("bankCode", "ABC");
            return infoBean;
        }
        if (bankNum.startsWith("6222") || bankNum.startsWith("95588") && bankNum.length() == 19) {
            infoBean.put("bankName", "中国工商银行");
            infoBean.put("bankCode", "ICBC");
            return infoBean;
        }
        if (bankNum.startsWith("6221") && bankNum.length() == 19) {
            infoBean.put("bankName", "中国邮政储蓄银行");
            infoBean.put("bankCode", "PSBC");
            return infoBean;
        }

        if (bankNum.startsWith("6013") || bankNum.startsWith("4563") && bankNum.length() == 19) {
            infoBean.put("bankName", "中国银行");
            infoBean.put("bankCode", "BOC");
            return infoBean;
        }
        if (bankNum.startsWith("6210") && bankNum.length() == 19) {
            infoBean.put("bankName", "农村信用社");
            infoBean.put("bankCode", "RCC");
            return infoBean;
        }
        if (bankNum.startsWith("6226") && bankNum.length() == 16) {
            infoBean.put("bankName", "中国民生银行");
            infoBean.put("bankCode", "CMBC");
            return infoBean;
        }
        if (bankNum.startsWith("6014") || bankNum.startsWith("4055") && bankNum.length() == 17) {
            infoBean.put("bankName", "交通银行");
            infoBean.put("bankCode", "COMM");
            return infoBean;
        }
        if (bankNum.startsWith("6222") && bankNum.length() == 19) {
            infoBean.put("bankName", "交通银行");
            infoBean.put("bankCode", "COMM");
            return infoBean;
        }
        if (bankNum.startsWith("622")) {
            infoBean.put("bankName", "中信银行");
            infoBean.put("bankCode", "CITIC");
            return infoBean;
        }
        return null;
    }

    public static Map<String, String> getBankInfoWithName(String name) {
        Map<String, String> infoBean = new HashMap<>();
        infoBean.put("bankName", name);
        int index = getBankNames().indexOf(name);
        if (index < 0) {
            return null;
        }
        infoBean.put("bankCode", bankCode[index]);
        return infoBean;
    }

    public static List<String> getBankNames() {
        return Arrays.asList(bankNames);
    }

    /**
     * 隐藏银行卡号
     * @param cardNo 银行卡号
     * @param displayDigit 末尾显示位数
     * @return
     */
    public static String maskCardNo(String cardNo, int displayDigit) {
        if (StrUtils.isEmpty(cardNo)) {
            return "";
        }
        int length = cardNo.length();
        return cardNo.substring(length - displayDigit);
    }
}
